import java.util.Scanner;
import java.util.Arrays;
public class Text {



    //冒泡排序
    public static int[] bubbleSort(int[] array){
        for (int j = 0; j < array.length -1 ; j++) {
            for (int i = 0; i < array.length - j - 1; i++) {
                boolean flg = false;
                if(array[i] > array[i+1]){
                    int tmp = array[i];
                    array[i] = array[i+1];
                    array[i+1] = tmp;
                    flg = true;
                }
            }
        }

        return array;

    }

    public static void main4(String[] args) {
        int[] array = new int[]{1,9,4,2,7,3,8};
        int[] flg = bubbleSort(array);

        String str = Arrays.toString(flg);
        System.out.println(str);
    }


    // 二分查找

    public static int binarySearch(int[] array,int tmp){
        int left = 0;
        int rigth = array.length - 1;
        while(left <= rigth){
            int mid = (left + rigth) / 2;
            if(array[mid] == tmp){
                return mid;
            }else if(array[mid] < tmp){
                left = mid + 1;
            }else{
                rigth = mid - 1;
            }
        }
        return -1;
    }

    public static void main3(String[] args) {
        int[] array = new int[]{1,2,3,4,5};
        int cmp = binarySearch(array,5);

        System.out.println(cmp);
    }


    //奇数位于偶数之前

    public static int[] aNew(int[] array){
        int left = 0;
        int right = array.length - 1;

        while(left <= right){
            if(array[left] % 2 == 0){ // 偶数
                int tmp = array[left];
                array[left] = array[right];
                array[right] = tmp;
            }
            left++;
            right--;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6,7,8,9};

        String str = Arrays.toString(aNew(array));
        System.out.println(str);
    }

    //       改变原有数组元素的值
    public static int[] transform(int[] array){
        int[] ret = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i] = array[i] * 2;
        }
        return ret;
    }


    public static void main1(String[] args) {
        int[] array = new int[]{1,2,3};
        int[] flg = transform(array);

        String str = Arrays.toString(flg);
        System.out.println(str);
    }
}
